<extend name="Public/base"/>
<block name="body">
	<!-- 标题 -->
	<div class="main-title">
		<h2>客户</h2>
	</div>

	<!-- 按钮工具栏 -->
	<div class="cf">
		<div class="fl">
            <button class="btn ajax-post" url="{:U('Client/setDis')}" target-form="ids">设为分销用户</button>
        </div>
		<!-- 高级搜索 -->
		<div class="search-form fr">
            <div class="sleft">
                <div class="drop-down">
                    <span id="sch-sort-txt" class="sort-txt" data="{$isDistributor}"><if condition="get_client_status_title($isDistributor) eq ''">所有<else/>{:get_client_status_title($isDistributor)}</if></span>
                    <i class="arrow arrow-down"></i>
                    <ul id="sub-sch-menu" class="nav-list hidden">
                        <li><a href="javascript:;" value="">所有</a></li>
                        <li><a href="javascript:;" value="1">分销用户</a></li>
                    </ul>
                </div>
                <input type="text" name="nickname" class="search-input" value="{:I('nickname')}" placeholder="请输入客户昵称">
                <a class="sch-btn" href="javascript:;" id="search" url="{:U()}"><i class="btn-search"></i></a>
            </div>
        </div>
	</div>

	<!-- 数据表格 -->
    <div class="data-table">
		<table>
            <!-- 表头 -->
            <thead>
                <tr>
                    <th class="row-selected row-selected">
                        <input class="check-all" type="checkbox">
                    </th>
                    <th>ID</th>
                    <th>昵称</th>
                    <th>头像</th>
                    <th>余额</th>
                    <th>上次登录时间</th>
                    <th>首次激活时间</th>
					<th>用户类型</th>
                </tr>
            </thead>

            <!-- 列表 -->
            <tbody>
                <volist name="list" id="data">
                    <tr>
                        <td><input class="ids" type="checkbox" value="{$data['id']}" name="ids[]"></td>
                        <td>{$data.id}</td>
                        <td>{$data.nickname}</td>
                        <td><img class="avatar" src="{$data.avatar}" /></td>
                        <td>{$data.balance|convert_amount}</td>
                        <td>{$data.lastLoginAt|format_unix_time}</td>
                        <td>{$data.activeAt|format_unix_time}</td>
                        <td>{$data.isDistributor|get_client_status_title} 
                            <if condition="$data.isDistributor eq 1">
                            <a href="{:U('Client/xiaxian')}&id={$data.id}" target="_blank">我的下线</a>
                            </if>
                        </td>
                    </tr>
                </volist>
            </tbody>
        </table>
	</div>
	<!-- 分页 -->
    <div class="page">
        {$_page}
    </div>
</div>

</block>
<block name="script">
    <script type="text/javascript">
        $(function(){
            //搜索功能
            $("#search").click(function(){
                var url = $(this).attr('url');
                var status = $("#sch-sort-txt").attr("data");
                var query  = $('.search-form').find('input').serialize();
                query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
                query = query.replace(/^&/g,'');
                if(status != ''){
                    query += 'status=' + status + "&" + query;
                }
                if( url.indexOf('?')>0 ){
                    url += '&' + query;
                }else{
                    url += '?' + query;
                }
                window.location.href = url;
            });
        
            /* 状态搜索子菜单 */
            $(".search-form").find(".drop-down").hover(function(){
                $("#sub-sch-menu").removeClass("hidden");
            },function(){
                $("#sub-sch-menu").addClass("hidden");
            });
            $("#sub-sch-menu li").find("a").each(function(){
                $(this).click(function(){
                    var text = $(this).text();
                    $("#sch-sort-txt").text(text).attr("data",$(this).attr("value"));
                    $("#sub-sch-menu").addClass("hidden");
                })
            });
        
            //回车自动提交
            $('.search-form').find('input').keyup(function(event){
                if(event.keyCode===13){
                    $("#search").click();
                }
            });
            
        })
    </script>
</block>
